package com.sky.mapper;

import com.sky.annotation.AutoFile;
import com.sky.dto.SetmealDTO;
import com.sky.entity.Setmeal;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface SetMealMapper {
    /**
     * 分页查询，返回count值
     * @return  long
     * */
    @Select("select count(*) from setmeal")
    Long pageCount() ;

    /**
     * 分页查询
     * @param start, pageSize, name, categoryId, status
     * @return List<Setmeal>
     * */
    List<SetmealVO> pageSplit(int start, int pageSize, String name,
                            Long categoryId, Integer status);

    /**
     * 根据分类id查询套餐的数量
     * @param id
     * @return
     */
    @Select("select count(id) from setmeal where category_id = #{categoryId}")
    Integer countByCategoryId(Long id);

    /**
     *  插入数据，新增操作
     * @return null
     * */
    // 插入setmeal
    @AutoFile(value = OperationType.INSERT)
    void insertSetMeal(Setmeal setmeal);

    /**
     * 查询setmeal套餐信息
     * @return SetmealVO
     * */
    SetmealVO getById(Long id);

    /**
     * 停售或起售套餐
     * @param status
     * @param id
     * */
    @Update("update setmeal set status = #{status} where id = #{id}")
    void startOrStop(Integer status, Long id);

    /**
     * 修改setmeal
     * @param setmeal
     * */
    @AutoFile(value = OperationType.UPDATE)
    void update(Setmeal setmeal);

    /**
     *  删除套餐setmeal
     * @param ids
     * */
    void deleteSetMeal(List<Long> ids);
                                        /*User*/
    /*---------------------------------------------------------------------------------------*/
    /**
     * 动态条件查询套餐
     * @param setmeal
     * @return
     */
    List<Setmeal> list(Setmeal setmeal);

    /**
     * 根据套餐id查询菜品选项
     * @param setmealId
     * @return
     */
    @Select("select sd.name, sd.copies, d.image, d.description " +
            "from setmeal_dish sd left join dish d on sd.dish_id = d.id " +
            "where sd.setmeal_id = #{setmealId}")
    List<DishItemVO> getDishItemBySetmealId(Long setmealId);
}
